Skip to content

Conversation

@monochromer
Copy link

We use server side rendering and useLayoutEffect spam into our logs with message:

useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.

@gravity-ui
Copy link
Contributor

gravity-ui bot commented Nov 17, 2025

🎭 Component Tests Report is ready.

@monochromer monochromer requested a review from ValeraS November 18, 2025 09:47
@monochromer monochromer changed the title fix(ThemeProvider): add useIsomorphicLayoutEffect to fix SSR warnings fix: add useIsomorphicLayoutEffect to fix SSR warnings Nov 18, 2025
@monochromer monochromer requested a review from ValeraS November 19, 2025 07:14
Copy link
Collaborator

@ValeraS ValeraS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add eslint rule to config

{
    selector: "MemberExpression[object.name='React'][property.name='useLayoutEffect']",
    message: "Please use 'src/hooks/useLayoutEffect' instead.",
},

@@ -0,0 +1,3 @@
import * as React from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the file to public hooks and rename it to useLayoutEffect.ts.

@monochromer monochromer force-pushed the isomorphic-theme-provider branch from db32e13 to 6007a57 Compare November 19, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants